package store.lunangangster.bpmn.converter.parser;

import javax.xml.stream.XMLStreamReader;
import store.lunangangster.bpmn.model.BaseElement;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.Event;
import store.lunangangster.bpmn.model.definition.MessageEventDefinition;

public class MessageEventDefinitionParser extends BaseChildElementParser {

  @Override
  public String getTargetName() {
    return ELEMENT_DEFINITION_MESSAGE;
  }

  @Override
  public void parseChild(XMLStreamReader xsr, BaseElement parentElement, BpmnModel model)
      throws Exception {
    if (parentElement instanceof Event) {
      MessageEventDefinition messageEventDefinition = new MessageEventDefinition();
      String messageRef = xsr.getAttributeValue(null, ATTRIBUTE_MESSAGE_REF);
      messageEventDefinition.setMessageRef(messageRef);
      ((Event) parentElement).getEventDefinitions().add(messageEventDefinition);

      parseChildElement(xsr, messageEventDefinition, getTargetName(), model);
    }
  }
}
